Practical-01
Problem Statement
Create an android program that will display "Hello World" in the middle of the screen with red color and also implement several callback events of the activity class.
Solution
To solve this problem, follow the steps below:
- Create a new Android project in Android Studio.
- Open the
activity_main.xmllayout file. - Add a
TextViewelement to the layout with the following attributes:android:id="@+id/helloWorldTextView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="Hello World"android:textColor="#FF0000"(red color)
- Open the
MainActivity.javafile. - Implement the necessary callback events of the
Activityclass, such asonCreate,onStart,onResume, etc. - In the
onCreatemethod, set the content view to theactivity_main.xmllayout file usingsetContentView(R.layout.activity_main). - Build and run the application on an Android device or emulator.
Explanation
In this solution, we create a simple Android application that displays the text "Hello World" in the middle of the screen with red color. We achieve this by adding a TextView element to the layout file and setting its attributes accordingly. Additionally, we implement the necessary callback events of the Activity class to handle the lifecycle of the application.
By following the above steps, you will be able to create an Android program that meets the requirements of the problem statement.